<cfcomponent output="false">

	<cffunction name="read" output="false" access="public" returntype="Organization">
		<cfargument name="id" required="true">
		<cfset var qRead="">
		<cfset var obj="">

		<cfquery username="#request.username#" password="#request.password#" name="qRead" datasource="nwharvest">
			select 	ID, ORG_NAME, ADMIN_ID, ORG_CAT_ID, LOGO_FILE	
			from dbo.ORGANIZATIONS
			where ID = <cfqueryparam cfsqltype="CF_SQL_INTEGER" value="#arguments.id#" />
		</cfquery>

		<cfscript>
			obj = createObject("component", "Organization").init();
			obj.ID = qRead.ID;
			obj.ORG_NAME = qRead.ORG_NAME;
			obj.ADMIN_ID = qRead.ADMIN_ID;
			obj.ORG_CAT_ID = qRead.ORG_CAT_ID;
			obj.LOGO_FILE = qRead.LOGO_FILE;
			return obj;
		</cfscript>
	</cffunction>

	<cffunction name="create" output="false" access="public">
		<cfargument name="bean" required="true" type="Organization">
		<cfset var qCreate="">
			
		<cfset var local1=arguments.bean.ORG_NAME>
	 	<cfset var local2=arguments.bean.ADMIN_ID>
		<cfset var local3=arguments.bean.ORG_CAT_ID>
		<cfset var local4=arguments.bean.LOGO_FILE>

		<cftransaction isolation="read_committed">
			<cfquery username="#request.username#" password="#request.password#" name="qCreate" datasource="nwharvest">
				insert into dbo.ORGANIZATIONS(ORG_NAME, ADMIN_ID, ADDRESS_ID, ORG_CAT_ID, LOGO_FILE)
				values (
					<cfqueryparam value="#local1#" cfsqltype="CF_SQL_VARCHAR" />,
					<cfqueryparam value="#local2#" cfsqltype="CF_SQL_INTEGER" null="#iif((local2 eq ""), de("yes"), de("no"))#" />,
					<cfqueryparam value="#local3#" cfsqltype="CF_SQL_INTEGER" null="#iif((local3 eq ""), de("yes"), de("no"))#" />,
					0,
					<cfqueryparam value="#local4#" cfsqltype="CF_SQL_VARCHAR" />
				)
				select @@Identity as pkID
			</cfquery>

		</cftransaction>

		<cfscript>
			arguments.bean.ID = qCreate.pkID;
		</cfscript>
		<cfreturn arguments.bean />
	</cffunction>

	<cffunction name="update" output="false" access="public">
		<cfargument name="bean" required="true" type="Organization">
		<cfset var qUpdate="">

		<cfquery username="#request.username#" password="#request.password#" name="qUpdate" datasource="nwharvest" result="status">
			update dbo.ORGANIZATIONS
			set ORG_NAME = <cfqueryparam value="#arguments.bean.ORG_NAME#" cfsqltype="CF_SQL_VARCHAR" />,
				ADMIN_ID = <cfqueryparam value="#arguments.bean.ADMIN_ID#" cfsqltype="CF_SQL_INTEGER" null="#iif((arguments.bean.ADMIN_ID eq ""), de("yes"), de("no"))#" />,
				ORG_CAT_ID = <cfqueryparam value="#arguments.bean.ORG_CAT_ID#" cfsqltype="CF_SQL_INTEGER" null="#iif((arguments.bean.ORG_CAT_ID eq ""), de("yes"), de("no"))#" />,
				LOGO_FILE = <cfqueryparam value="#arguments.bean.LOGO_FILE#" cfsqltype="CF_SQL_VARCHAR" />
			where ID = <cfqueryparam value="#arguments.bean.ID#" cfsqltype="CF_SQL_INTEGER">
		</cfquery>
		<cfreturn arguments.bean />
	</cffunction>

	<cffunction name="delete" output="false" access="public" returntype="void">
		<cfargument name="bean" required="true" type="virtualfooddrive-inf.com.Organization">
		<cfset var qDelete="">

		<cfquery username="#request.username#" password="#request.password#" name="qDelete" datasource="nwharvest" result="status">
			delete
			from dbo.ORGANIZATIONS
			where ID = <cfqueryparam cfsqltype="CF_SQL_INTEGER" value="#arguments.bean.ID#" />
		</cfquery>

	</cffunction>

</cfcomponent>